home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7955 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ernie.idi.oclc.org!usenet
  2. From: Ron Unterreiner <runterreiner@idi.oclc.org>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: No struct in C++!!?
  5. Date: Thu, 15 Feb 1996 08:23:40 -0800
  6. Organization: Information Dimensions, Inc.
  7. Message-ID: <31235E0C.252C@idi.oclc.org>
  8. References: <1996Feb14.151620.5532@queens-belfast.ac.uk>
  9. NNTP-Posting-Host: runterr.idi.oclc.org
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win16; I)
  14.  
  15. Georg Woste wrote:
  16. > Hi,
  17. > a beginners question: I found in different C++ books examples of C++ programms
  18. > which contain type declarations and definitions in the main() programm - for
  19. > example a struct  - as in C.
  20. > My question is, whether this is a contradiction
  21. > to the paradigm of C++. Shouldn't be everything in a C++ programm
  22. > either classes, objects or the interaction between objects?
  23. > So is it bad C++ style, to use functions or data outside from
  24. > classes (objects)?
  25. > Thanks!
  26. > Georg Woeste
  27.  
  28. A class is a struct.  Anywhere you see the word struct you can substitute 
  29. the word class.  The major thing a class gives you that a C struct 
  30. doesn't is the ability to protect data.  You can control the way the data 
  31. in the class is accessed from outside by writing methods.  It works much 
  32. like stacks and queues where you would define AddMember, DeleteMember and 
  33. TraverseMember functions.  In a nutshell, a class is a really powerful 
  34. struct.  You can define a class like a C struct though by making all your 
  35. data public.  This is usually a bad idea because the data in the class 
  36. could get stepped on accidently if you are not careful.  The whole 
  37. purpose of classes is to restrict access to the data inside.
  38.